package com.zff.rental.controller.user;


import com.zff.rental.AppConstant;
import com.zff.rental.common.PageVo;
import com.zff.rental.common.Result;
import com.zff.rental.service.user.UserServer;
import com.zff.rental.vo.user.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户管理
 *
 * @author HCY
 */
@RestController
@RequestMapping(AppConstant.RM_USER_MANAGE)
public class UserManageController {

    @Resource
    private UserServer userServer;

    /**
     * 添加用户
     */
    @PostMapping("/add")
    public Result<UserVo> add(@RequestBody AddUserParams params) {
        UserVo result = userServer.add(params);
        return Result.success(result);
    }

    /**
     * 修改用户
     */
    @PostMapping("/modify")
    public Result<UserVo> modify(@Validated @RequestBody ModifyUserParams params) {
        UserVo result = userServer.modify(params);
        return Result.success(result);
    }

    /**
     * 用户详情
     */
    @GetMapping("/details")
    public Result<UserVo> details(@RequestParam("userId") Long userId) {
        UserVo userInfo = userServer.details(userId);
        return Result.success(userInfo);
    }

    /**
     * 所有用户列表
     */
    @GetMapping("/allList")
    public Result<List<UserVo>> allList() {
        List<UserVo> result = userServer.allList();
        return Result.success(result);
    }

    /**
     * 用户列表
     */
    @PostMapping("/list")
    public Result<PageVo<UserVo>> list(@RequestBody UserListParams params) {
        PageVo<UserVo> result = userServer.list(params);
        return Result.success(result);
    }

    /**
     * 重置密码
     */
    @PostMapping("/resetPassword")
    public Result<Boolean> resetPassword(@RequestBody ResetPasswordParams params) {
        Boolean result = userServer.resetPassword(params);
        return Result.success(result);
    }

}
